/*
{
"状态":1,
"名称":"复制-菜单信息",
"作者":"马学兵",
"创建时间":"2018-09-01",
"功能":"复制-菜单信息",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/

DECLARE @menu_key CHAR(32)
DECLARE @father_menu CHAR(32)
declare @port varchar(100)

set @menu_key='{menu_key}'
set @father_menu='{father_menu}'
set @port='{port}'

IF ISNULL(@father_menu,'')=''
BEGIN
	RAISERROR ('SQL:父级菜单不允许为空', 16 ,1 ) ; 
	return 
END  
IF (@menu_key=@father_menu)
BEGIN
	RAISERROR ('SQL:父级/子级菜单不允许相同', 16 ,1 ) ; 
	return 
END  

if exists(SELECT 1 FROM dbo.y_menu WHERE menu_key=@menu_key AND port=@port)
begin
	RAISERROR ('SQL:不运行在同一个项目中复制菜单', 16 ,1 ) ; 
	return 
end  

INSERT INTO y_menu([menu_key], [father_menu], [menu_code], [menu_name], [icon], [port], [route_url], [order_index], [create_time], [update_time], [menu_power_id])
SELECT REPLACE(NEWID(),'-','') As[menu_key], @father_menu AS [father_menu], [menu_code], [menu_name], [icon], @port, [route_url], [order_index], [create_time], [update_time], [menu_power_id]
FROM y_menu WHERE menu_key=@menu_key